using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.NetworkInformation;

namespace Utilities.Unix.Net.Wlan
{
    public class WlanInterface : Utilities.Net.Wlan.WlanInterface
    {
        public override string SSID
        {
            get { throw new System.NotImplementedException(); }
        }
        public override int Channel
        {
            get
            {
                return default(int);
            }
        }
        public override int RSSI
        {
            get
            {
                return default(int);
            }
        }
        
        private NetworkInterface baseInterface;
        
        public WlanInterface(NetworkInterface networkInterface)
        {
            baseInterface = networkInterface;
        }
        
        public override IPInterfaceProperties GetIPProperties()
        {
            return baseInterface.GetIPProperties();
        }
        public override IPv4InterfaceStatistics GetIPv4Statistics()
        {
            throw new System.NotImplementedException();
        }

        public override string Description
        {
            get { throw new System.NotImplementedException(); }
        }

        public override PhysicalAddress GetPhysicalAddress()
        {
            throw new System.NotImplementedException();
        }

        public override string Id
        {
            get { throw new System.NotImplementedException(); }
        }

        public override bool IsReceiveOnly
        {
            get { throw new System.NotImplementedException(); }
        }

        public override string Name
        {
            get { throw new System.NotImplementedException(); }
        }

        public override NetworkInterfaceType NetworkInterfaceType
        {
            get { throw new System.NotImplementedException(); }
        }

        public override OperationalStatus OperationalStatus
        {
            get { throw new System.NotImplementedException(); }
        }

        public override long Speed
        {
            get { throw new System.NotImplementedException(); }
        }

        public override bool Supports(NetworkInterfaceComponent networkInterfaceComponent)
        {
            throw new System.NotImplementedException();
        }

        public override bool SupportsMulticast
        {
            get { throw new System.NotImplementedException(); }
        }
    }
    
    public class WlanClient : Utilities.Net.Wlan.WlanClient
    {
        public override List<Utilities.Net.Wlan.WlanInterface> Interfaces { get; set; }
        
        public WlanClient()
        {
            Interfaces = new List<Utilities.Net.Wlan.WlanInterface>();
   
            var ifs = NetworkInterface.GetAllNetworkInterfaces();
   
            Process p = new Process();
            p.StartInfo.FileName = "iwconfig";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.Start();
   
            WlanInterface wlanInterface;
   
            while (!p.StandardOutput.EndOfStream)
            {
                string data = p.StandardOutput.ReadLine();
    
                // Nouvelle interface
                if (!data.StartsWith(" ") && data != "")
                {
                    string ifName = data.Remove(data.IndexOf(' '));
                    wlanInterface = new WlanInterface(ifs.Single(i => i.Name == ifName));
                    Interfaces.Add(wlanInterface);
                }
                
                
            }
        }
    }
}